package com.whfc.wxmp.api.emp.controller;

import com.whfc.common.base.BaseController;
import com.whfc.common.result.*;
import com.whfc.common.util.JSONUtil;
import com.whfc.common.util.SessionAttr;
import com.whfc.emp.dto.*;
import com.whfc.emp.entity.AppExamPaperQuestion;
import com.whfc.emp.param.*;
import com.whfc.entity.dto.WxDeviceBindCheckDTO;
import com.whfc.entity.param.WxBindCheckParam;
import com.whfc.fuum.entity.SysUser;
import com.whfc.fuum.entity.WxUser;
import com.whfc.safety.dto.MdSafetyCheckDTO;
import com.whfc.wxmp.annotation.CurrentMsUser;
import com.whfc.wxmp.annotation.CurrentWxUser;
import com.whfc.wxmp.api.emp.service.WxEmpService;
import com.whfc.wxmp.api.emp.service.WxTrainingService;
import com.whfc.wxmp.util.RequestConetxtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.util.List;

/**
 * 小程序中的题库
 *
 * @author realm
 * @Description:
 * @date 2025年09月25日
 */
@RestController
@RequestMapping("/mp/api/training")
public class WxTrainingController extends BaseController {

    @Autowired
    private WxTrainingService wxTrainingService;


    /**
     * 题库列表
     *
     * @return
     */
    @GetMapping(value = "/list")
    public Result list(AppTrainingListParam param) {
        PageData<AppTrainingDTO> pageData = wxTrainingService.getTrainingList(param);
        return ResultUtil.success(pageData);
    }

    /**
     * 题库分类列表
     *
     * @return
     */
    @GetMapping(value = "/cateList")
    public Result categoryList() {
        return ResultUtil.success(wxTrainingService.categoryList());
    }


    /**
     * 题库试题列表
     *
     * @param reqParam
     * @return
     */
    @GetMapping(value = "/questionList")
    public Result questionList(
            AppTrainingQuestionListParam reqParam) {
        PageData<AppTrainingQuestionsDTO> pageData = wxTrainingService.questionList(reqParam);
        return ResultUtil.success(pageData);
    }


    /**
     * 培训答题
     *
     * @param reqParam
     * @return
     */
    @PostMapping(value = "/trainingAnswer")
    public Result trainingAnswer(
            @CurrentWxUser WxUser loginUser,
            @RequestBody AppTrainingAnswerAddParam reqParam) {
        reqParam.setUserId(loginUser.getId());
        return wxTrainingService.trainingAnswer(reqParam);
    }

    /**
     * 我的答题记录
     *
     * @param reqParam
     * @return
     */
    @GetMapping(value = "/trainingUserProgress")
    public Result trainingUserProgress(
            @CurrentWxUser WxUser loginUser,
            AppTrainingUserProgressListParam reqParam) {
        reqParam.setUserId(loginUser.getId());
        return wxTrainingService.trainingUserProgress(reqParam);
    }

    /**
     * 试卷列表
     *
     * @param reqParam
     * @return
     */
    @GetMapping(value = "/examList")
    public Result examList(
            AppExamPaperListParam reqParam) {
        PageData<AppExamPaperDTO> pageData = wxTrainingService.examList(reqParam);
        return ResultUtil.success(pageData);
    }


    /**
     * 试题列表
     *
     * @param reqParam
     * @return
     */
    @GetMapping(value = "/examQuestionList")
    public Result examQuestionList(
            AppExamPaperQuestionListParam reqParam) {
        PageData<AppExamPaperQuestionDTO> pageData = wxTrainingService.examQuestionList(reqParam);
        return ResultUtil.success(pageData);
    }

    /**
     * banner数据
     *
     * @return
     */
    @GetMapping(value = "/banner")
    public Result bannerData() {
        return ResultUtil.success(wxTrainingService.bannerList());
    }
    /**
     * 开始考试
     *
     * @param loginUser @param request
     * @return
     */
    @PostMapping("/examing")
    public Result examing(@CurrentWxUser WxUser loginUser, @RequestBody AppExamRecordAddParam request) {
        request.setUserId(loginUser.getId());
        return wxTrainingService.examing(request);
    }
    /**
     * 考试记录
     *
     * @param loginUser
     * @param request
     * @return
     */
    @GetMapping("/examRecordPage")
    public Result examRecordPage(@CurrentWxUser WxUser loginUser, @Validated AppExamRecordListParam request) {
        request.setUserId(loginUser.getId());
        PageData<AppExamRecordDTO> pageData = wxTrainingService.examRecordPage(request);
        return ResultUtil.success(pageData);
    }
}
